/* 
 * File:   CFile.h
 * Author: faraj
 *
 * Created on October 7, 2009, 5:58 PM
 */

#ifndef _CFILE_H
#define	_CFILE_H
#include <fstream>
#include "CWrapper.h"

class CFile
{
private:
    string path;
    ifstream *fread;
    ofstream *fwrite;
    bool excisting;
    
public:
    CFile(string pathx)
    {
        this->path = pathx;
    }
    
   
    bool generateStreams(bool read, bool write)
    {
        if(read)
        {
            this->fread = new ifstream(path.c_str(), ios::in | ios::binary);
            if(!fread->is_open())
                return false;   
        }
        if(write)
        {
            this->fwrite = new ofstream(path.c_str(), ios::out | ios::binary);
            if(!fwrite->is_open())
                return false;
        }
        return true;
    }
    
    bool closeStreams(bool read, bool write)
    {
        if(read)
            this->fread->close();
        if(write)
            this->fwrite->close();
        return true;
    }
    
    ifstream* getReadStream()
    {
        return fread;
    }
    
    ofstream* getWriteStream()
    {
        return fwrite;
    }
    
    string getPath()
    {
        return path;
    }
    
    bool deleteFile()
    {
        return remove(this->path.c_str()) == 0;
    }
    
    ~CFile()
    {
        fread->close();
        fwrite->close();
    }
};
#endif	/* _CFILE_H */

